package com.mllweb.api.core.base;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 服务基类
 */
public class BaseService {
    /**
     * 当前Request
     */
    protected HttpServletRequest request;
    /**
     * 当前Response
     */
    protected HttpServletResponse response;
    /**
     * 当前Session
     */
    protected HttpSession session;
    /**
     * 当前Cookie
     */
    protected Cookie[] cookies;

    public BaseService() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        this.request = attributes.getRequest();
        this.response = attributes.getResponse();
        this.session = this.request.getSession(true);
        this.cookies = this.request.getCookies();
    }
}